package world.snowcrystal.dto;


import jakarta.annotation.Nullable;
import lombok.Data;
import lombok.NoArgsConstructor;
import world.snowcrystal.Enum.ChatroomMessageCodeEnum;

@Data
@NoArgsConstructor
public class ChatroomMessage {
    private String username;
    private String id;
    private Integer code;
    private final Long timestamp = System.currentTimeMillis();

    @Nullable
    private String message;

    public ChatroomMessage(String username, String id, ChatroomMessageCodeEnum code, String message) {
        this(username, id, code.getCode(), message);
    }
    public ChatroomMessage(String username, String id, Integer code, @Nullable String message) {
        this.username = username;
        this.id = id;
        this.code = code;
        this.message = message;
    }

    public double retrieveTimestampAsDouble(){
        return Double.longBitsToDouble(timestamp);
    }

    public static ChatroomMessage chat(String username,String id,String message) {
        return new ChatroomMessage(username,id, ChatroomMessageCodeEnum.NORMAL,message);
    }
    public static ChatroomMessage leave(String username) {
        return new ChatroomMessage("System",String.valueOf(0), ChatroomMessageCodeEnum.LEAVE,username);
    }
    public static ChatroomMessage enter(String username) {
        return new ChatroomMessage("System",String.valueOf(0), ChatroomMessageCodeEnum.ENTER,username);
    }

    public static ChatroomMessage announce(String message) {
        return new ChatroomMessage("System",String.valueOf(0), ChatroomMessageCodeEnum.ANNOUNCEMENT,message);
    }


}
